package com.yun.springbootsecurity.controller;

import com.yun.springbootsecurity.pojo.Role;
import com.yun.springbootsecurity.pojo.User;
import com.yun.springbootsecurity.service.RoleService;
import com.yun.springbootsecurity.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
public class UserController {

    private final UserService userService;
    private final RoleService roleService;

    public UserController(UserService userService, RoleService roleService) {
        this.userService = userService;
        this.roleService = roleService;
    }

    @RequestMapping("/user")
    @ResponseBody
    public String selectByUserId(String username){
        User user = userService.selectByUserId(username);
        return user.toString();
    }

    @RequestMapping("/user/role")
    @ResponseBody
    public String selectByRole(String roleId){
        Role role = roleService.selectByRole(roleId);
        return role.toString();
    }
    @RequestMapping("/roles/role")
    @ResponseBody
    public String select1(){
        return "/roles/role";
    }
    @RequestMapping("/role")
    @ResponseBody
    public String select2(){
        return "/role";
    }

}
